﻿using AdminStyem.Application.Command.CultivationCommand;
using AdminStyem.Application.DTO;
using AdminStyem.Domain.Entity;
using AdminStyem.Repositories;
using MediatR;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AdminStyem.Application.CommandHandler.CultivatioHandler
{
    public class VaccineShowCommandHandler : IRequestHandler<VaccineShowCommand, APIResult<List<VaccineDTO>>>
    {
        IBaseRespository<Vaccine> BaseVaccion;

        public VaccineShowCommandHandler(IBaseRespository<Vaccine> baseVaccion)
        {
            BaseVaccion = baseVaccion;
        }

        public Task<APIResult<List<VaccineDTO>>> Handle(VaccineShowCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<VaccineDTO>> ret = new APIResult<List<VaccineDTO>>();
            ret.Code = ResultCode.查询成功;
            ret.Message = ResultCode.查询成功.ToString();

            var vaccines = BaseVaccion.Queryable()
                                      .Where(v => v.VaccineId == request.VaccineId && !v.IsDeleted)
                                      .Select(v => new VaccineDTO
                                      {
                                          VaccineId = v.VaccineId,
                                          FeedingDay = v.FeedingDay,
                                          Manner = v.Manner,
                                          Method = v.Method,
                                          DynamicPhoto = v.DynamicPhoto,
                                          IsDeleted = v.IsDeleted
                                      }).ToList();

            ret.Data = vaccines;

            return Task.FromResult(ret);
        }
    }
}
